/**
 * <p>
 * Created on 2006-4-17 16:24:29 <br>
 * Copyright (c) 2006, All rights reserved.
 * </p>
 * @author Widen
 */
package com.widen.prima;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import com.widen.prima.system.entites.Language;
import com.widen.prima.system.entites.Properties;
import com.widen.prima.util.Util;

public class Messages
{
    private static final String BUNDLE_NAME = "com.widen.prima.messages"; //$NON-NLS-1$

    public static ResourceBundle resourceBundle;
    static
    {
        String language = Util.propertiesService
            .getProperty(Properties.LANGUAGE.getValue());
        int currLanguage = 0;
        if (language != null && language.trim().length() > 0)
        {
            currLanguage = Integer.parseInt(language);
        }
        if (currLanguage == Language.CHINESE.getValue())
        {
            resourceBundle = ResourceBundle
                .getBundle(BUNDLE_NAME, Locale.CHINA);
        } else
        {
            resourceBundle = ResourceBundle.getBundle(BUNDLE_NAME, Locale.US);
        }
    }

    private Messages()
    {
    }

    public static String getString(String key)
    {
        try
        {
            return resourceBundle.getString(key);
        } catch (MissingResourceException e)
        {
            e.printStackTrace();
            return '!' + key + '!';
        }
    }
}
